package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.CureMethodDAO;
import cn.edu.scau.cmi.hombio.dao.CureTaskMethodDAO;
import cn.edu.scau.cmi.hombio.dao.CureTypeDAO;

import cn.edu.scau.cmi.hombio.domain.CureMethod;
import cn.edu.scau.cmi.hombio.domain.CureTaskMethod;
import cn.edu.scau.cmi.hombio.domain.CureType;

import cn.edu.scau.cmi.hombio.service.CureTypeService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for CureType entities
 * 
 */

@Controller("CureTypeRestController")

public class CureTypeRestController {

	/**
	 * DAO injected by Spring that manages CureMethod entities
	 * 
	 */
	@Autowired
	private CureMethodDAO cureMethodDAO;

	/**
	 * DAO injected by Spring that manages CureTaskMethod entities
	 * 
	 */
	@Autowired
	private CureTaskMethodDAO cureTaskMethodDAO;

	/**
	 * DAO injected by Spring that manages CureType entities
	 * 
	 */
	@Autowired
	private CureTypeDAO cureTypeDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for CureType entities
	 * 
	 */
	@Autowired
	private CureTypeService cureTypeService;

	/**
	 * Show all CureTaskMethod entities by CureType
	 * 
	 */
	@RequestMapping(value = "/CureType/{curetype_id}/cureTaskMethods", method = RequestMethod.GET)
	@ResponseBody
	public List<CureTaskMethod> getCureTypeCureTaskMethods(@PathVariable Integer curetype_id) {
		return new java.util.ArrayList<CureTaskMethod>(cureTypeDAO.findCureTypeByPrimaryKey(curetype_id).getCureTaskMethods());
	}

	/**
	* Create a new CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureTaskMethods", method = RequestMethod.POST)
	@ResponseBody
	public CureTaskMethod newCureTypeCureTaskMethods(@PathVariable Integer curetype_id, @RequestBody CureTaskMethod curetaskmethod) {
		cureTypeService.saveCureTypeCureTaskMethods(curetype_id, curetaskmethod);
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethod.getId());
	}

	/**
	* View an existing CureMethod entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureMethods/{curemethod_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureMethod loadCureTypeCureMethods(@PathVariable Integer curetype_id, @PathVariable Integer related_curemethods_id) {
		CureMethod curemethod = cureMethodDAO.findCureMethodByPrimaryKey(related_curemethods_id, -1, -1);

		return curemethod;
	}

	/**
	* Delete an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureTaskMethods/{curetaskmethod_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTypeCureTaskMethods(@PathVariable Integer curetype_id, @PathVariable Integer related_curetaskmethods_id) {
		cureTypeService.deleteCureTypeCureTaskMethods(curetype_id, related_curetaskmethods_id);
	}

	/**
	* Select an existing CureType entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureType loadCureType(@PathVariable Integer curetype_id) {
		return cureTypeDAO.findCureTypeByPrimaryKey(curetype_id);
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Create a new CureType entity
	* 
	*/
	@RequestMapping(value = "/CureType", method = RequestMethod.POST)
	@ResponseBody
	public CureType newCureType(@RequestBody CureType curetype) {
		cureTypeService.saveCureType(curetype);
		return cureTypeDAO.findCureTypeByPrimaryKey(curetype.getId());
	}

	/**
	* Save an existing CureType entity
	* 
	*/
	@RequestMapping(value = "/CureType", method = RequestMethod.PUT)
	@ResponseBody
	public CureType saveCureType(@RequestBody CureType curetype) {
		cureTypeService.saveCureType(curetype);
		return cureTypeDAO.findCureTypeByPrimaryKey(curetype.getId());
	}

	/**
	* Show all CureMethod entities by CureType
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureMethods", method = RequestMethod.GET)
	@ResponseBody
	public List<CureMethod> getCureTypeCureMethods(@PathVariable Integer curetype_id) {
		return new java.util.ArrayList<CureMethod>(cureTypeDAO.findCureTypeByPrimaryKey(curetype_id).getCureMethods());
	}

	/**
	* Create a new CureMethod entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureMethods", method = RequestMethod.POST)
	@ResponseBody
	public CureMethod newCureTypeCureMethods(@PathVariable Integer curetype_id, @RequestBody CureMethod curemethod) {
		cureTypeService.saveCureTypeCureMethods(curetype_id, curemethod);
		return cureMethodDAO.findCureMethodByPrimaryKey(curemethod.getId());
	}

	/**
	* Save an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureTaskMethods", method = RequestMethod.PUT)
	@ResponseBody
	public CureTaskMethod saveCureTypeCureTaskMethods(@PathVariable Integer curetype_id, @RequestBody CureTaskMethod curetaskmethods) {
		cureTypeService.saveCureTypeCureTaskMethods(curetype_id, curetaskmethods);
		return cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(curetaskmethods.getId());
	}

	/**
	* Show all CureType entities
	* 
	*/
	@RequestMapping(value = "/CureType", method = RequestMethod.GET)
	@ResponseBody
	public List<CureType> listCureTypes() {
		return new java.util.ArrayList<CureType>(cureTypeService.loadCureTypes());
	}

	/**
	* Save an existing CureMethod entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureMethods", method = RequestMethod.PUT)
	@ResponseBody
	public CureMethod saveCureTypeCureMethods(@PathVariable Integer curetype_id, @RequestBody CureMethod curemethods) {
		cureTypeService.saveCureTypeCureMethods(curetype_id, curemethods);
		return cureMethodDAO.findCureMethodByPrimaryKey(curemethods.getId());
	}

	/**
	* View an existing CureTaskMethod entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureTaskMethods/{curetaskmethod_id}", method = RequestMethod.GET)
	@ResponseBody
	public CureTaskMethod loadCureTypeCureTaskMethods(@PathVariable Integer curetype_id, @PathVariable Integer related_curetaskmethods_id) {
		CureTaskMethod curetaskmethod = cureTaskMethodDAO.findCureTaskMethodByPrimaryKey(related_curetaskmethods_id, -1, -1);

		return curetaskmethod;
	}

	/**
	* Delete an existing CureType entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureType(@PathVariable Integer curetype_id) {
		CureType curetype = cureTypeDAO.findCureTypeByPrimaryKey(curetype_id);
		cureTypeService.deleteCureType(curetype);
	}

	/**
	* Delete an existing CureMethod entity
	* 
	*/
	@RequestMapping(value = "/CureType/{curetype_id}/cureMethods/{curemethod_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteCureTypeCureMethods(@PathVariable Integer curetype_id, @PathVariable Integer related_curemethods_id) {
		cureTypeService.deleteCureTypeCureMethods(curetype_id, related_curemethods_id);
	}
}